home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Button / Sources / ButtonPart.cpp next >
Encoding:
Text File  |  1994-04-21  |  4.2 KB  |  152 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ButtonPart.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef _BUTTONPART_
  14. #include "ButtonPart.h"
  15. #endif
  16.  
  17. // ----- Framework Includes -----
  18.  
  19. #ifndef FWUTIL_H
  20. #include <FWUtil.h>
  21. #endif
  22.  
  23. #ifndef FWPOINT_H
  24. #include <FWPoint.h>
  25. #endif
  26.  
  27. #ifndef FWRECT_H
  28. #include <FWRect.h>
  29. #endif
  30.  
  31. // ----- OpenDoc Includes -----
  32.  
  33. #ifndef _SHAPE_
  34. #include <Shape.h>
  35. #endif
  36.  
  37. // ----- Macintosh Includes -----
  38.  
  39. #ifndef mathRoutinesIncludes
  40. #include <math routines.h>
  41. #endif
  42.  
  43. #ifndef __QUICKDRAW__
  44. #include <QuickDraw.h>
  45. #endif
  46.  
  47. #pragma segment buttonpart
  48.  
  49. //==============================================================================
  50. //    •• class CButtonPart
  51. //==============================================================================
  52.  
  53. //------------------------------------------------------------------------------
  54. //    • CButtonPart::CButtonPart
  55. //------------------------------------------------------------------------------
  56.  
  57. CButtonPart::CButtonPart()
  58. {
  59. }
  60.  
  61. //------------------------------------------------------------------------------
  62. //    • CButtonPart::~CButtonPart
  63. //------------------------------------------------------------------------------
  64.  
  65. CButtonPart::~CButtonPart()
  66. {
  67. }
  68.  
  69. //------------------------------------------------------------------------------
  70. //    • CButtonPart::CreateControlHandle
  71. //------------------------------------------------------------------------------
  72.  
  73. ControlHandle CButtonPart::CreateControlHandle(XMPPlatformWindow window, const FW_CRect& controlRect)
  74. {
  75.     FW_SPlatformRect rect = controlRect;
  76.     return ::NewControl(window, &rect, "\pOK", TRUE, 0, 0, 1, pushButProc, (long)this);
  77. }
  78.  
  79. //----------------------------------------------------------------------------------------
  80. //    • CButtonPart::GetContentPropertyValueType
  81. //----------------------------------------------------------------------------------------
  82.  
  83. XMPValueType CButtonPart::GetContentPropertyValueType() const
  84. {
  85.     return kSampleButtonKind;
  86. }
  87.  
  88. //------------------------------------------------------------------------------
  89. //    • CButtonPart::NewFrame
  90. //------------------------------------------------------------------------------
  91.  
  92. FW_CFrame* CButtonPart::NewFrame(XMPFrame* xmpFrame, XMPTypeToken presentation)
  93. {
  94. FW_UNUSED(presentation);
  95.     
  96.     CButtonFrame *frame = new CButtonFrame;
  97.     frame->InitButtonFrame(xmpFrame, this);
  98.     return frame;
  99. }
  100.  
  101. //==============================================================================
  102. //    •• class CButtonFrame
  103. //==============================================================================
  104.  
  105. //------------------------------------------------------------------------------
  106. //    • CButtonFrame::CButtonFrame
  107. //------------------------------------------------------------------------------
  108.  
  109. CButtonFrame::CButtonFrame()
  110. {
  111. }
  112.  
  113. //------------------------------------------------------------------------------
  114. //    • CButtonFrame::InitButtonFrame
  115. //------------------------------------------------------------------------------
  116.  
  117. void CButtonFrame::InitButtonFrame(XMPFrame* frame, FW_CPart* part)
  118. {
  119.     InitCtlMgrFrame(frame, part);
  120. }
  121.  
  122. //------------------------------------------------------------------------------
  123. //    • CButtonFrame::~CButtonFrame
  124. //------------------------------------------------------------------------------
  125.  
  126. CButtonFrame::~CButtonFrame()
  127. {
  128. }
  129.  
  130. //------------------------------------------------------------------------------
  131. //    • CButtonFrame::UpdateUsedShape
  132. //------------------------------------------------------------------------------
  133.  
  134. void CButtonFrame::UpdateUsedShape()
  135. {    
  136.     FW_CPoint controlSize;
  137.     ((CButtonPart*)GetPart())->GetControlSize(controlSize);
  138.     FW_SPlatformRect controlRect;
  139.     ::SetRect(&controlRect, 0, 0, FixedToInt(controlSize.x), FixedToInt(controlSize.y));
  140.     
  141.     FW_PlatformRegion rgn = ::NewRgn();
  142.     ::InsetRect(&controlRect, -1, -1);
  143.     ::OpenRgn();
  144.     ::FrameRoundRect(&controlRect, 16, 16);
  145.     ::CloseRgn(rgn);
  146.     
  147.     XMPShape* scratch = ::NewXMPShape(rgn);
  148.     scratch->Intersect(GetXMPFrame()->GetFrameShape());
  149.     GetXMPFrame()->ChangeUsedShape(scratch);
  150. }
  151.  
  152.